package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.User;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    //发验证码
    @PostMapping("/user/sendMsg")
    public ResultInfo sendMsg(@RequestBody Map<String, String> param) {
        //接收手机号
        String phone = param.get("phone");
        //调用service
        userService.sendMsg(phone);
        return ResultInfo.success();
    }

    //登录
    @PostMapping("/user/login")
    public ResultInfo login(@RequestBody Map<String, String> param) {
        //取手机号，和验证码
        String phone = param.get("phone");
        String code = param.get("code");
        //调用service
        ResultInfo resultInfo = userService.login(phone, code);
        return resultInfo;
    }

    //退出
    @PostMapping("/user/logout")
    public ResultInfo logout() {
        userService.logout();
        return ResultInfo.success();
    }
}
